<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>indexOfSubstrings</title>
</head>
<body>
    <h1>'tiktok tok tok tik tok tik',中查找'tik'，返回索引数组:</h1>
    <div id="content"></div>
    <script>
        const indexOfSubstrings = function* (str,searchValue){
            let i = 0;
            while(true){
                const r = str.indexOf(searchValue,i);
                if(r === -1){
                    return;
                }
                yield r;
                i = r + 1;
            }
        }
        document.querySelector('#content').innerHTML = JSON.stringify([...indexOfSubstrings('tiktok tok tok tik tok tik','tik')])
    </script>
</body>
</html>